package com.beagle.njddapp.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.beagle.njddapp.R;
import com.beagle.njddapp.bean.CompanyBean;
import com.beagle.njddapp.bean.CompanyBean;
import com.beagle.njddapp.ui.adapter.inter.RecyclerViewItemClickLisenter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author hxx
 * @date 2021-03-19 18:46
 * 消息adapter
 */
public class CompanyListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<CompanyBean> companyBeans;
    private Context context;
    private RecyclerViewItemClickLisenter<CompanyBean> onItemClickLisenter;

    public void setOnItemClickLisenter(RecyclerViewItemClickLisenter<CompanyBean> onItemClickLisenter) {
        this.onItemClickLisenter = onItemClickLisenter;
    }

    private View.OnClickListener onClickListener=new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            CompanyBean companyBean= (CompanyBean) view.getTag();
            onItemClickLisenter.onItemClickLisenter(companyBean);
        }
    };

    public CompanyListAdapter(List<CompanyBean> companyBeans, Context context) {
        this.companyBeans = companyBeans;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_zd,null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MyHolder myHolder= (MyHolder) holder;
        CompanyBean companyBean=companyBeans.get(position);
        myHolder.tvZd.setText(companyBean.getName());
        myHolder.itemView.setTag(companyBean);
        myHolder.itemView.setOnClickListener(onClickListener);

    }

    @Override
    public int getItemCount() {
        return companyBeans.size();
    }
    public class MyHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.tv_zd)
        TextView tvZd;


        public MyHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
